package com.yanqu.road.server.gameplayer.module.activity.goddess;

import com.yanqu.road.entity.activity.goddess.*;
import com.yanqu.road.entity.activity.goddess.config.*;
import com.yanqu.road.pb.activity.GoddessProto;
import com.yanqu.road.server.manger.ServerLanguageMgr;
import com.yanqu.road.utils.string.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class GoddessPb {

    public static GoddessProto.GoddessUserDataTemp.Builder buildUserData(GoddessUserData userData) {
        GoddessProto.GoddessUserDataTemp.Builder builder = GoddessProto.GoddessUserDataTemp.newBuilder();
        builder.setEnergy(userData.getEnergy());
        builder.setLastEnergyRecTime(userData.getLastEnergyRecTime());
        builder.setHumanNum(userData.getHumanNum());
        builder.setEra(userData.getEra());
        builder.setMakeYear(userData.getMakeYear());
        builder.setColorStonePoint(userData.getCellPoint());
        for (GoddessCell goddessCell : userData.getCellList()) {
            GoddessProto.GoddessCellDataTemp.Builder cellBuilder = buildCellData(goddessCell);
            builder.addCell(cellBuilder);
        }

        for (GoddessColorStone colorStone : userData.getColorStoneMap().values()) {
            GoddessProto.GoddessColorStoneTemp.Builder colorStoneBuilder = buildColorStoneData(colorStone);
            builder.addColorStone(colorStoneBuilder);
        }

        for (GoddessYinYangStone yinStone : userData.getYinStoneList()) {
            GoddessProto.GoddessYinYangStoneTemp.Builder yiStoneBuilder = buildYiStoneData(yinStone);
            builder.addYinStone(yiStoneBuilder);
        }

        for (GoddessYinYangStone yangStone : userData.getYangStoneList()) {
            GoddessProto.GoddessYinYangStoneTemp.Builder yiStoneBuilder = buildYiStoneData(yangStone);
            builder.addYangStone(yiStoneBuilder);
        }

        for (Map.Entry<Integer, Integer> entry : userData.getPeoMap().entrySet()) {
            GoddessProto.GoddessPeopleDataTemp.Builder peoBuild = GoddessProto.GoddessPeopleDataTemp.newBuilder();
            peoBuild.setPeoId(entry.getKey());
            peoBuild.setNum(entry.getValue());
            builder.addPeople(peoBuild);
        }

        //其他数据
        GoddessProto.GoddessYearStatusTemp.Builder statusBuilder = buildStatusData(userData);
        builder.setStatus(statusBuilder);
        return builder;
    }

    public static GoddessProto.GoddessYearStatusTemp.Builder buildStatusData(GoddessUserData userData) {
        GoddessProto.GoddessYearStatusTemp.Builder statusBuilder = GoddessProto.GoddessYearStatusTemp.newBuilder();
        statusBuilder.setYearOfEar(userData.getYearStatus().getYearOfEar());
        statusBuilder.setMissionId(userData.getYearStatus().getMissionId());
        return statusBuilder;
    }


    public static GoddessProto.GoddessYinYangStoneTemp.Builder buildYiStoneData(GoddessYinYangStone yinStone) {
        GoddessProto.GoddessYinYangStoneTemp.Builder yiStoneBuilder = GoddessProto.GoddessYinYangStoneTemp.newBuilder();
        yiStoneBuilder.setId(yinStone.getId());
        yiStoneBuilder.setPos(yinStone.getPos());
        yiStoneBuilder.setType(yinStone.getType());
        yiStoneBuilder.setLv(yinStone.getLv());
        return yiStoneBuilder;
    }

    public static GoddessProto.GoddessColorStoneTemp.Builder buildColorStoneData(GoddessColorStone colorStone) {
        GoddessProto.GoddessColorStoneTemp.Builder colorStoneBuilder = GoddessProto.GoddessColorStoneTemp.newBuilder();
        colorStoneBuilder.setId(colorStone.getId());
        colorStoneBuilder.setShapeId(colorStone.getSd());
        colorStoneBuilder.setCellId(colorStone.getCell());
        colorStoneBuilder.setPoint(colorStone.getPt());
        colorStoneBuilder.setShape(colorStone.getFs());
        colorStoneBuilder.setRotate(colorStone.getRe());
        return colorStoneBuilder;
    }

    public static GoddessProto.GoddessCellDataTemp.Builder buildCellData(GoddessCell goddessCell) {
        GoddessProto.GoddessCellDataTemp.Builder cellBuilder = GoddessProto.GoddessCellDataTemp.newBuilder();
        cellBuilder.setPos(goddessCell.getPos());
        cellBuilder.setOpen(goddessCell.getOpen());
        cellBuilder.setStoneId(goddessCell.getStoneId());
        return cellBuilder;
    }


    public static GoddessProto.GoddessEraInfoTemp.Builder buildEarInfo(GoddessEraInfo eraInfo, String language) {
        GoddessProto.GoddessEraInfoTemp.Builder builder = GoddessProto.GoddessEraInfoTemp.newBuilder();
        builder.setEraId(eraInfo.getEraId());
        builder.setUpNeed(eraInfo.getUpNeed());
        builder.setEnergyCost(eraInfo.getEnergyCost());
        builder.setEnergyMax(eraInfo.getEnergyMax());
        builder.setEnergyResume(eraInfo.getEnergyResume());
        builder.setEraReward(eraInfo.getEraReward());
        builder.setPeopleUpParam(eraInfo.getPeopleUpParam());
        builder.setPointParam(eraInfo.getPointParam());
        builder.setPeopleNum(eraInfo.getPeopleNum());
        return builder;
    }

    public static GoddessProto.GoddessLiangYiStoneInfoTemp.Builder buildLiangYiStone(GoddessLiangYiStoneInfo stoneInfo, String language) {
        GoddessProto.GoddessLiangYiStoneInfoTemp.Builder builder = GoddessProto.GoddessLiangYiStoneInfoTemp.newBuilder();
        builder.setLiangYiLv(stoneInfo.getLiangYiLv());
        builder.setAddEffect(stoneInfo.getAddEffect());
        builder.setTurnNum(stoneInfo.getTurnNum());
        builder.setUpCost(stoneInfo.getUpCost());
        return builder;
    }

    public static GoddessProto.GoddessRandomShapeInfoTemp.Builder buildShapeInfo(GoddessRandomStoneInfo shapeInfo, String language) {
        GoddessProto.GoddessRandomShapeInfoTemp.Builder builder = GoddessProto.GoddessRandomShapeInfoTemp.newBuilder();
        builder.setShapeId(shapeInfo.getShapeId());
        builder.setShape(shapeInfo.getShape());
        builder.setShapeType(shapeInfo.getShapeType());
        builder.setShapePoint(shapeInfo.getShapePoint());
        return builder;
    }

    public static GoddessProto.GoddessActivityMissionInfoTemp.Builder buildMission(GoddessMissionInfo missionInfo, String language) {
        GoddessProto.GoddessActivityMissionInfoTemp.Builder builder = GoddessProto.GoddessActivityMissionInfoTemp.newBuilder();
        builder.setMissionId(missionInfo.getMissionId());
        builder.setLandInfo(missionInfo.getLandInfo());
        builder.setTargetPoint(missionInfo.getTargetPoint());
        builder.setShapeWeight(missionInfo.getShapeWeight());
        builder.setPeopleUpParam(missionInfo.getPeopleUpParam());
        builder.setReward(missionInfo.getReward());
        //builder.setEnergyCost(missionInfo.getEnergyCost());
        builder.setBackId(missionInfo.getBackId());
        return builder;
    }

    public static void main(String[] args) {

        System.out.println(rotateRight("0;0;0|1;0;0|1;1;0", 3, 3));
    }

    public static String rotateRight(String formStr, int row, int col){
        List<List<Integer>> destList = new ArrayList<>();
        List<List<Integer>> srcList = new ArrayList<>();
        for (int i = 0; i < row; i++) {
            srcList.add(new ArrayList<>());
            destList.add(new ArrayList<>());
        }
        List<String> formStrList = StringUtils.stringToStringList(formStr, "\\|");
        for (int i = 0; i < formStrList.size(); i++) {
            srcList.set(i, StringUtils.stringToIntegerList(formStrList.get(i), ";"));
        }
        for (List<Integer> list : destList) {
            while (list.size() < col){
                list.add(0);
            }
        }
        for (List<Integer> list : srcList) {
            while(list.size() < col){
                list.add(0);
            }
        }
        for (int i = 0; i < srcList.size(); i++) {
            List<Integer> list = srcList.get(i);
            for (int k = 0; k < list.size(); k++) {
                destList.get(k).set(i, list.get(k));
            }
        }
        List<String> result = new ArrayList<>();
        for (int i = destList.size() - 1; i >= 0; i--) {
            result.add(StringUtils.listToString(destList.get(i), ";"));
        }
        return StringUtils.listToString(result, "|");
    }
}
